package com.flurry.sdk;

import com.flurry.sdk.ji;
import java.io.Closeable;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;

public final class hu {
    private static final String a = hu.class.getSimpleName();

    public static ji a(File file) {
        FileInputStream fileInputStream;
        DataInputStream dataInputStream;
        ji jiVar;
        if (file == null || !file.exists()) {
            return null;
        }
        ji.a aVar = new ji.a();
        try {
            fileInputStream = new FileInputStream(file);
            try {
                dataInputStream = new DataInputStream(fileInputStream);
            } catch (Exception e) {
                e = e;
                dataInputStream = null;
                try {
                    km.a(3, a, "Error loading legacy agent data.", e);
                    ly.a((Closeable) dataInputStream);
                    ly.a((Closeable) fileInputStream);
                    jiVar = null;
                    return jiVar;
                } catch (Throwable th) {
                    th = th;
                    ly.a((Closeable) dataInputStream);
                    ly.a((Closeable) fileInputStream);
                    throw th;
                }
            } catch (Throwable th2) {
                th = th2;
                dataInputStream = null;
                ly.a((Closeable) dataInputStream);
                ly.a((Closeable) fileInputStream);
                throw th;
            }
            try {
                if (dataInputStream.readUnsignedShort() != 46586) {
                    km.a(3, a, "Unexpected file type");
                    ly.a((Closeable) dataInputStream);
                    ly.a((Closeable) fileInputStream);
                    return null;
                }
                int readUnsignedShort = dataInputStream.readUnsignedShort();
                if (readUnsignedShort != 2) {
                    km.a(6, a, "Unknown agent file version: " + readUnsignedShort);
                    ly.a((Closeable) dataInputStream);
                    ly.a((Closeable) fileInputStream);
                    return null;
                }
                jiVar = (ji) aVar.a(dataInputStream);
                ly.a((Closeable) dataInputStream);
                ly.a((Closeable) fileInputStream);
                return jiVar;
            } catch (Exception e2) {
                e = e2;
                km.a(3, a, "Error loading legacy agent data.", e);
                ly.a((Closeable) dataInputStream);
                ly.a((Closeable) fileInputStream);
                jiVar = null;
                return jiVar;
            }
        } catch (Exception e3) {
            e = e3;
            dataInputStream = null;
            fileInputStream = null;
            km.a(3, a, "Error loading legacy agent data.", e);
            ly.a((Closeable) dataInputStream);
            ly.a((Closeable) fileInputStream);
            jiVar = null;
            return jiVar;
        } catch (Throwable th3) {
            th = th3;
            dataInputStream = null;
            fileInputStream = null;
            ly.a((Closeable) dataInputStream);
            ly.a((Closeable) fileInputStream);
            throw th;
        }
    }
}
